package org.forward;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ForwardServletTest extends HttpServlet {

	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		System.out.println(">>>ServletA: " + ForwardServletTest.class.getName());
		System.out.println(">>>开始加法运算业务。。。");
		String numA = req.getParameter("numA");
		String numB = req.getParameter("numB");
		int a = Integer.valueOf(numA);
		int b = Integer.valueOf(numB);
		System.out.println(">>>运算结果：" + (a + b));
		System.out.println(">>>将结果转发到ServletB处理。。。");
		req.setAttribute("rs", a + b);
		System.out.println("---------------------------------------------------");
		RequestDispatcher dispatcher = req.getRequestDispatcher("forwardLater");
		dispatcher.forward(req, resp);
	}
}
